/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn;

import cn.webrx.config.AppConfig;
import cn.webrx.mapper.BookMapper;
import cn.webrx.mapper.DbMapper;
import cn.webrx.pojo.Book;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.List;

/**
 * <p>Project: spring2021 - Demo
 * <p>Powered by webrx On 2021-11-02 20:34:28
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = AppConfig.class)
public class Demo {

    @Autowired
    private ApplicationContext ctx;

    @Autowired
    private DbMapper dm;

    @Autowired
    private BookMapper bm;

    @Test
    public void t3(){
        //未分页
        //System.out.println(bm.queryAll());

        System.out.println(bm.tbs());

        //使用分页
        int currpage = 0;
        int pagesize = 5;
        PageHelper.startPage(currpage,pagesize);
        var pi = PageInfo.of(bm.tbs());

        for(String book : pi.getList()){
            System.out.println(book);
        }
        currpage = pi.getPageNum();
        int pagecount = pi.getPages();
        pagesize = pi.getPageSize();
        long recordcount = pi.getTotal();
        String pinfo = String.format("第%d页，共%d页 每页%d条，共%d条",currpage,pagecount,pagesize,recordcount);
        System.out.println(pinfo);

    }

    @Test
    public void t2(){
        //System.out.println(dm.tbs());
        //System.out.println(dm.dbs());
        System.out.println(bm.queryAll());
        System.out.println(bm.query());
    }

    @Test
    public void t1(){
        for(String s : ctx.getBeanDefinitionNames()){
            System.out.println(s);
        }
    }
}
